//获取url参数
var params = param();
var id,position_coord;
//提交任务
function add(){
	$.ajax({
		type: "get",
		url: ctx + "/weixin/addUserTask?task_id=" + params.task_id + "&openid="+params.openid,
		success: function(result) {
			id=result.id;
			location.href="task.html?id="+id+"&openid="+param().openid + "&position_coord="+params.position_coord;
		},
		error: function(err) {
			console.error(err);
			$.alert("系统异常！");
		}
	});
}
//提交任务信息
function commit(){
	var phone = $("#phone").val();
	var description = $("#description").val();
	$.ajax({
		type: "get",
		url: ctx + "/weixin/updateUserTask",
		data:{'id':id,'phone':phone,'description':description,'state':1},
		success: function(result) {
			location ="task_list.html?openid="+params.openid;
		},
		error: function(err) {
			console.error(err);
			$.alert("系统异常！");
		}
	});
}
function cancel(){
	$.ajax({
		type: "get",
		url: ctx + "/weixin/deletetUserTask",
		data:{'id':id}
	});
	location ="task_list.html?openid="+params.openid;
}
$("#filePicker").click(function(){
	$("#map").height("38%");
	$(".weui_cells_form").css({"height":"45%"});
});
$(function(){
	if(params.state == 'add'){
		add();
	}else{
		id=params.id;
		$.getScript(ctx + "/web/weixin/js/getting-started.js", function(){
		  	uploader.options.server=ctx + "/weixin/addImage?task_user_id="+params.id;
		});
	}
	var position_coord = JSON.parse(param().position_coord);
	//初始化地图
	var map = new AMap.Map('map', {
		zoom: 17,
		center: position_coord
	});
	var marker = new AMap.Marker({
	  position: position_coord,
	  draggable: true,
	  cursor: 'move'
	});
	marker.setMap(map);
	//设置点标记的动画效果，此处为弹跳效果
	//marker.setAnimation('AMAP_ANIMATION_BOUNCE');
});
